//
//  SDLoginViewController.m
//  skinDetection
//
//  Created by  liangzhun on 2018/10/29.
//  Copyright © 2018年  liangzhun. All rights reserved.
//

#import "SDLoginViewController.h"
#import "SDBoundPhoneNumberVC.h"
#import "SDVerCodeLoginViewController.h"
@interface SDLoginViewController ()

@end

@implementation SDLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    self.thirdLoginBtn.layer.cornerRadius = 5.f;
    self.thirdLoginBtn.layer.masksToBounds = YES;
    [self.thirdLoginBtn setBackgroundColor:SDMainColor];
    
    self.codeLoginBtn.layer.cornerRadius = 5.f;
    self.codeLoginBtn.layer.masksToBounds = YES;
    [self.codeLoginBtn setBackgroundColor:SDMainColor];
    
    self.logoImage.layer.cornerRadius = 20.f;
    self.logoImage.layer.masksToBounds = YES;
    [self showLoginThird];
    
}

/**
 判断是否显示第三方登录
 */
- (void)showLoginThird
{
    [SDNetwork getTurnThirdLoginFinish:^(NSDictionary * _Nullable dic, NSError * _Nullable error) {
        if (!error) {
            if ([dic[@"data"][@"third_login_switch"] integerValue] == 1) {
                 self.thirdLoginBtn.hidden = NO;
                 self.codeLoginBtn.hidden = YES;
            }else{
                self.thirdLoginBtn.hidden = YES;
                self.codeLoginBtn.hidden = NO;
            }
        }
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

/**
 第三方登录
 */
- (IBAction)thirdLogin:(UIButton *)sender {
    
    [SDMethodTool loginWeChatWithViewController:self action:^{
        //登录成功后判断是否绑定手机号，如果绑定就进入主页，未绑定就进入绑定手机号页面
        SDAppDelegate.userModel.userName.length == 0 ?[self goBoundPhoneNumberVC]:[SDAppDelegate goTabbar];
        
    }];
}

- (IBAction)goVerCodeVC:(UIButton *)sender {
    [self goVerCodeLoginVC];
}

/**
 进入绑定手机号页面
 */
- (void)goBoundPhoneNumberVC
{
        SDBoundPhoneNumberVC *vc = [SDMethodTool getViewControlWithIdentifier:NSStringFromClass([SDBoundPhoneNumberVC class])];
        [self.navigationController pushViewController:vc animated:YES];
}

/**
 进入手机号登录页面
 */
- (void)goVerCodeLoginVC
{
    SDVerCodeLoginViewController *vc = [SDMethodTool getViewControlWithIdentifier:NSStringFromClass([SDVerCodeLoginViewController class])];
    [self.navigationController pushViewController:vc animated:YES];
}
@end
